import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { UserList, UserBeanData, OrgUserBeanData, UserSessionBeanData, UserSelectBeanData } from '@/model/system/user/model'

export function loadUserByDeptId (data: CommonSearch) {
  return request<UserList>({
    url: '/starUser/loadUserByDeptId',
    data: data,
    method: 'post'
  })
}

/**
 * 根据角色获取对应用户
 * @param data
 */
export function loadUserByRoleId (data: CommonSearch) {
  return request<UserList>({
    url: '/starUser/loadUserByRoleId',
    data: data,
    method: 'post'
  })
}

export function getRoleSelectedUser (fid: string) {
  return request({
    url: `/starGrant/getGrantData?fid=${fid}&type=1`
  })
}

/**
 * 根据角色获取对应用户
 * @param data
 */
export function loadAllUserTree (data: UserSelectBeanData) {
  return request<StarTreeNode[]>({
    url: '/userSelect/loadAllUserTree',
    data: data,
    method: 'post'
  })
}

export function loadUserById (id: string) {
  return request<UserBeanData>({
    url: `/starUser/loadUserById?id=${id}`,
    method: 'get'
  })
}

export function deleteUser (uid: string, deptId:string) {
  return request({
    url: `/starUser/removeUser?uid=${uid}&deptId=${deptId}`,
    method: 'post'
  })
}

export function saveUser (formData: UserBeanData) {
  return request({
    url: '/starUser/saveUser',
    data: formData,
    method: 'post'
  })
}

export function saveOrgUser (formData: OrgUserBeanData) {
  return request({
    url: '/starUser/saveOrgUser',
    data: formData,
    method: 'post'
  })
}

export function getMaxIndex (fid: string) {
  return request<string>({
    url: `/starUser/getMaxIndex?fid=${fid}`
  })
}

export function getUserInfo () {
  return request<UserSessionBeanData>({
    url: '/starUser/getUserInfo'
  })
}

/**
 * 设置兼职部门/主部门
 * @param formData
 */
export function putPartTimeDept (uid:string, deptIds:string, isMain:string) {
  return request({
    url: `/starUser/putPartTimeDept?uid=${uid}&deptIds=${deptIds}&isMain=${isMain}`,
    method: 'post'
  })
}

/**
 * 用户部门关系列表
 * @param data
 */
export function loadUserPartTimeDept (data: CommonSearch) {
  return request<UserList>({
    url: '/starUser/loadUserPartTimeDept',
    data: data,
    method: 'post'
  })
}
